package cn.iocoder.yudao.module.trade.mq.producer;

import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import cn.iocoder.yudao.module.trade.mq.message.OrderDeliveryMessage;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
 * Order 相关消息的 Producer
 *
 * @author cai
 */
@Slf4j
@Component
public class OrderDeliveryProducer {

    @Resource
    private ApplicationContext applicationContext;

    /**
     * 发送 {@link OrderDeliveryMessage} 消息
     *
     * @param order 订单
     * @param orderItems 订单商品
     */
    public void sendOrderDeliveryMessage(TradeOrderDO order, List<TradeOrderItemDO> orderItems) {
        OrderDeliveryMessage message = new OrderDeliveryMessage()
                .setOrder(order).setOrderItems(orderItems);
        applicationContext.publishEvent(message);
    }

}
